﻿namespace EFS.RC.ConversationBrowser.Controls.Actions
{
	public partial class Play : EFS.RC.ConversationBrowser.Controls.Control
	{
		#region Constructors
		/// Implicit
		public Play()
		{
			InitializeComponent();
		}
		#endregion

		#region Properties
		/// Property ConversationDate: Get, Set
		public System.DateTime ConversationDate { get; set; }

		/// Property ConversationGuid: Get, Set
		public System.Guid ConversationGuid { get; set; }

		/// Property MediaSource: Get
		public System.Uri MediaSource
		{
			get
			{
				// create
				System.Uri mediaSourceUri =
					new System.Uri(
						System.String.Format("{0}/Media/{1}/{2}.wma",
							EFS.RC.ConversationBrowser.Common.Main.HostFullUrl,
							ConversationDate.ToString("yyyy-MM-dd").Replace("-", "/"),
							EFS.Common.Functions.Guid.Strip(ConversationGuid)));

				// ok
				return mediaSourceUri;
			}
		}
		#endregion

		#region Events
		/// Loaded
		private void Player_Loaded(object sender, System.Windows.RoutedEventArgs e)
		{
			// ignore in design tool
			if (!System.ComponentModel.DesignerProperties.IsInDesignTool)
			{
				// make playlist
				Microsoft.SilverlightMediaFramework.Core.Media.PlaylistItem playlistItem = new Microsoft.SilverlightMediaFramework.Core.Media.PlaylistItem();
				playlistItem.DeliveryMethod = Microsoft.SilverlightMediaFramework.Plugins.Primitives.DeliveryMethods.Streaming;
				playlistItem.MediaSource = MediaSource;

				// add play list
				controlPlayer.Playlist.Add(playlistItem);
			}
		}
		#endregion
	}

}